package com.yisoo.ubag.iot.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class MyMQConfig {

    //@Bean Binding，Queue，Exchange

    /**
     * 容器中的 Binding，Queue，Exchange 都会自动创建（RabbitMQ没有的情况）
     * RabbitMQ 只要有。@Bean声明属性发生变化也不会覆盖
     * @return
     */
    @Bean
    public Queue ubagQueueSub() {
        Queue queue = new Queue("ubag.queue.sub", true, false, false);
        return queue;
    }
    @Bean
    public Queue ubagQueuePub() {
        Queue queue = new Queue("ubag.queue.pub", true, false, false);
        return queue;
    }

    @Bean
    public Exchange ubagExchangePub() {
        //String name, boolean durable, boolean autoDelete, Map<String, Object> arguments
       return new TopicExchange("ubag.exchange.pub",true,false);
    }

    @Bean
    public Exchange ubagExchangeSub() {
        //String name, boolean durable, boolean autoDelete, Map<String, Object> arguments
        return new TopicExchange("ubag.exchange.sub",true,false);
    }

    @Bean
    public Binding mqttPubBingding() {
        return new Binding("ubag.queue.pub",
                Binding.DestinationType.QUEUE,
                "ubag.exchange.pub",
                "mqtt.pub",
                null);

    }
    @Bean
    public Binding mqttSubBingding() {
        return new Binding("ubag.queue.sub",
                Binding.DestinationType.QUEUE,
                "ubag.exchange.sub",
                "mqtt.sub",
                null);
    }
}
